<?php

	/*
		Filename: Config.php
		Description: Makes connection to the database and includes
		all classes.
		
		Last Edit: 12-08-2012 (dd-mm-yyyy)
	*/
	
	// Inlcude database
	require_once("Config.php");
	
	/*
		Setting functions
	*/
	function GetSetting($key)
	{
		$key = mysql_real_escape_string($key);
		$Result = mysql_query("SELECT * FROM settings WHERE `keys`='$key'") or die(mysql_error());
		while($Row = mysql_fetch_array($Result))
		{
			return $Row['value'];
		}
		return false;
	}
	
	/*
		Group Functions
	*/
	function getGroups()
	{
		$Groups = array();
		$Result = mysql_query("SELECT * FROM groups");
		while($Row = mysql_fetch_array($Result))
		{
			$Group = new Group();
			$Group->Id = $Row['group_id'];
			$Group->Name = $Row['group_name'];
			$Groups[] = $Group;
		}
		return $Groups;
	}
	
	function getGroup($id)
	{
		$id = mysql_real_escape_string($id);
		$Result = mysql_query("SELECT * FROM groups WHERE group_id='$id'");
		while($Row = mysql_fetch_array($Result))
		{
			$Group = new Group();
			$Group->Id = $Row['group_id'];
			$Group->Name = $Row['group_name'];
			return $Group;
		}
		return false;
	}
	
	/* 
		Student Functions
	*/
	function getStudents($groupid)
	{
		$Students = array();
		$groupid = mysql_real_escape_string($group);
		$Result = mysql_query("SELECT * FROM users WHERE group_id='$groupid'");
		while($Row = mysql_fetch_array($Result))
		{
			$Student = new Student();
			$Student->Id = $Row['user_id'];
			$Student->GroupId = $Row['group_id'];
			$Student->Name = $Row['user_name'];
			$Student->Password=  $Row['user_password'];
			$Student->Username = $Row['user_nick'];
			$Students[] = $Student;
		}
		return $Students;
	}
	
	function getStudent($studentid)
	{
		$studentid = mysql_real_escape_string($studentid);
		$Result = mysql_query("SELECT * FROM users WHERE user_id='$studentid'");
		while($Row = mysql_fetch_array($studentid))
		{
			$Student = new Student();
			$Student->Id = $Row['user_id'];
			$Student->GroupId = $Row['group_id'];
			$Student->Name = $Row['user_name'];
			$Student->Password=  $Row['user_password'];
			$Student->Username = $Row['user_nick'];
			return $Student;
		}
		return false;
	}
	
	/*
		Overige Functies
	*/
	function IntLink($page)
	{
		return "./index.php?p=$page";
	}
	
	/*
		Admin Functions
	*/
	function getAdmin($username)
	{
		$Admin = new Admin();
		$Result = mysql_query("SELECT * FROM admins WHERE admin_username='$username'");
		while($Row = mysql_fetch_array($Result))
		{
			$Admin->Id = $Row['admin_id'];
			$Admin->Password = $Row['admin_password'];
			$Admin->Username = $Row['admin_username'];
			return $Admin;
		}
		return false;
	}
	
	function isAdmin()
	{
		if(isset($_SESSION['admin_id'])) return true;
		else return false;
	}